# 导包

from api.login import LoginAPI
from api.dept import DeptAPI
from common.assertutil import common_assert


# 测试用例
class TestLoginAPI:
    token666 = None
    id666 = None

    # 前置条件
    def setup_class(self):
        self.login_api = LoginAPI()
        self.dept_api = DeptAPI()

    # 登录成功
        response = self.login_api.login(login_data={"mobile": "13800000002", "password": "123456"})
        # 提取data并保存
        TestLoginAPI.token666=response.json().get("data")
        print(TestLoginAPI.token666)

    # 获取部门
    def test01_insert_dept(self):
        response = self.dept_api.insert_dept(TestLoginAPI.token666)
        print(response.json())
        # common_assert(response)
        # 断言
        assert response.status_code == 200
        assert response.json().get("success") is True
        assert response.json().get("code") == 10000
        assert "成功" in response.text

    # 添加部门
    def test02_add_dept(self):
        response = self.dept_api.add_dept(TestLoginAPI.token666, add_data={"name": "策划部", "code": "1030304"})
        print(response.json())
        TestLoginAPI.id666 = response.json().get("data").get("id")
        print(TestLoginAPI.id666)
        # 断言
        common_assert(response)

    # 查询部门
    def test03_get_dept(self):
        response = self.dept_api.get_dept(TestLoginAPI.id666, TestLoginAPI.token666)
        print(response.json())
        # 断言
        common_assert(response)

    # 修改部门
    def test04_update_dept(self):
        response = self.dept_api.update_dept(TestLoginAPI.id666, TestLoginAPI.token666, update_data={"name": "策划部2"})
        print(response.json())
        # 断言
        common_assert(response)

    # 删除部门
    def test05_delete_dept(self):
        response = self.dept_api.delete_dept(TestLoginAPI.id666, TestLoginAPI.token666)
        print(response.json())
        # 断言
        common_assert(response)
